package com.qianfeng.wuyang.himalaya.adapter.anchoradapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qianfeng.wuyang.himalaya.R;
import com.qianfeng.wuyang.himalaya.bean.anchorbean.list;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */

public class Fragment_AnchorAdapt extends RecyclerView.Adapter<Fragment_AnchorAdapt.VierHolder> {
    private List<list> list;

    private Context context;
    private LayoutInflater inflater;


    public Fragment_AnchorAdapt( Context context) {
       list=new ArrayList<>();
        this.context = context;
        inflater=LayoutInflater.from(context);
    }


    @Override
    public VierHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View view= inflater.inflate(R.layout.layout_anchor,parent,false);

        VierHolder holder=new VierHolder(view);
       return holder;

     }

    @Override
    public void onBindViewHolder(VierHolder holder, int position) {

       if(list.get(position).getList()!=null){

           holder.textView.setText(list.get(position).getTitle());
           holder.textView2.setText(list.get(position).getList().get(0).getNickname());
           holder.textView3.setText(list.get(position).getList().get(1).getNickname());
           holder.textView4.setText(list.get(position).getList().get(2).getNickname());
           Picasso.with(context)
                   .load(list.get(position).getList().get(0).getSmallLogo())
                   .into(holder.imageView);
           Picasso.with(context)
                   .load(list.get(position).getList().get(1).getSmallLogo())
                   .into(holder.imageView2);
           Picasso.with(context)
                   .load(list.get(position).getList().get(2).getSmallLogo())
                   .into(holder.imageView3);

         }else{

//          holder.textView.setText(list.get(position).getTitle());
      }
    }



    @Override
    public int getItemCount() {
        return list.size();
    }



    public void addAll(Collection<? extends com.qianfeng.wuyang.himalaya.bean.anchorbean.list> collection){
        int size = list.size();
        list.addAll(collection);
        notifyItemRangeInserted(size,collection.size());
    }

    public  static class VierHolder extends RecyclerView.ViewHolder{
       private TextView textView, textView2,textView3,textView4;
        private ImageView imageView,imageView2,imageView3;


      public VierHolder(View itemView) {
            super(itemView);
          textView= (TextView) itemView.findViewById(R.id.anchor_item);

          textView2= (TextView) itemView.findViewById(R.id.achor_texiview2);
          textView3= (TextView) itemView.findViewById(R.id.achor_texiview3);
          textView4= (TextView) itemView.findViewById(R.id.achor_item2);
          imageView= (ImageView) itemView.findViewById(R.id.anchor_imageView);
          imageView2= (ImageView) itemView.findViewById(R.id.anchor_imageView2);
          imageView3= (ImageView) itemView.findViewById(R.id.anchor_imageView3);

   }
    }





}
